var userNameStr;
var pwdStr;
var flag=false;
$(function() {
	$("#userName").focus(function(){
		$("#userName").css("background-color","#FFFFCC");
	});
	$("#userName").blur(function(){
		userNameCheck();
	});
	$("#pwd").focus(function(){
		$("#pwd").css("background-color","#FFFFCC");
	});
	$("#pwd").blur(function(){
		pwdCheck();
	});
});

function inputCheck()
{
	userNameCheck();
	pwdCheck();
}

function userNameCheck(){
	$("#userName").css("background-color","#FFFFFF");
	 userNameStr= $("#userName").val();
	if(userNameStr==null||userNameStr=="")
	{
		flag=false;
		$("#userName").focus();
		$("#userNameMsg").html("用户名不能为空！");
		$("#userNameMsg").removeClass().addClass("error");
	}else{
		flag=true;
		$("#userNameMsg").html("通过验证！");
		$("#userNameMsg").removeClass().addClass("right");
	}
}
function pwdCheck(){
	$("#pwd").css("background-color","#FFFFFF");
	 pwdStr= $("#pwd").val();
	if(pwdStr==null||pwdStr=="")
	{
		flag=false;
		$("#pwd").focus();
		$("#pwdMsg").html("密码不能为空！");
		$("#pwdMsg").removeClass().addClass("error");
	}else{
		flag=true;
		$("#pwdMsg").html("通过验证！");
		$("#pwdMsg").removeClass().addClass("right");
	}
}



function login() {
	inputCheck();
	if(flag){
		$("#pwd").val(CryptoJS.SHA1(pwdStr));
		$.ajax({
			url:"user/login",
			type:"POST",
			data:{"user_name":userNameStr,"password":$("#pwd").val()},
			dataType:"json",
			success:function(data){
				if(data.status){
					window.location.href="/edu/index.html";
				}else{
					$(".input").val("");					
					$("#userNameMsg").html("用户名或密码错误！");
					$("#userNameMsg").removeClass().addClass("error");
					$("#pwdMsg").html("用户名或密码错误！");
					$("#pwdMsg").removeClass().addClass("error");
					$("#userName").focus();
				}
			}
		});
	}
}

function logout() {
	window.parent.document.getElementById("loginFrame").src = "/edu/user/login.html";
}

function register() {
	window.parent.location.href = "/edu/user/register.html"
}
